package com.kemai.designmode.ui
import android.os.Bundle
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.ui.BaseActivity
import com.kemai.designmode.R
import com.kemai.designmode.factory.abstract.AbstractFactory
import com.kemai.designmode.factory.abstract.AppleAbstractFactory
import com.kemai.designmode.factory.abstract.BananaAbstractFactory
import com.kemai.designmode.factory.abstract.OrangeAbstractFactory
import com.kemai.designmode.observer.CustomerObserver

import com.kemai.designmode.observer.MangoAttention
import com.kemai.designmode.observer.jdk.Customer

import com.kemai.designmode.observer.jdk.Mango






//观察者模式调用(一个对象状态改变时通知其他对象)
class ObserverActivity : BaseActivity(), ItemClickListener {
    private val studyContent = arrayOf("自定义观察","jdk")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_content)
        findViewById()
        setTiTle("观察者模式")
        setAdapterContent(studyContent,ObserverActivity@this,ObserverActivity@this)
    }

    override fun itemClick(position: Int) {
        when(position){
            0->{

                val attentions = MangoAttention() //目标
                attentions.add(CustomerObserver("刘一凡"))
                attentions.add(CustomerObserver("陈航"))
                attentions.add(CustomerObserver("童帅"))
                attentions.add(CustomerObserver("山山"))
                //到货
                attentions.perform()
            }
            1->{
                val attentions = Mango("芒果")
                attentions.addObserver(Customer("刘一凡"))
                attentions.addObserver(Customer("陈航"))
                attentions.addObserver(Customer("童帅"))
                attentions.addObserver(Customer("山山"))
                attentions.perform()
            }
        }
    }

}